Ext.namespace("Budget");

Budget.Finished = function() {
	this.winView = null;
	this.winMsg=null;
	this.remind=null;
	this.storeYear=new Ext.data.ArrayStore({
	        	fields: ['value', 'name'],
	        	data: OMS.DEPT_YEAR
	    });	
	this.cbYear = new Ext.form.ComboBox({
		width: 100,
		name:'budgetYear',
		store:this.storeYear ,
		valueField: 'value',
        displayField: 'name',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.storeYear.insert(0,new this.storeYear.recordType({value:'',name:'全部'}, 101));
	this.storeMonth= new Ext.data.ArrayStore({
	        	fields: ['value', 'name'],
	        	data: OMS.DEPT_MONTH
	    });
	this.cbMonth = new Ext.form.ComboBox({
		width: 100,
		name:'budgetMonth',
		store:this.storeMonth,
		valueField: 'value',
        displayField: 'name',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.storeMonth.insert(0,new this.storeMonth.recordType({value:'',name:'全部'}, 101));
	
    this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找预算表'},
        handler: this.queryBudget,
        scope: this
    });
		
	this.store = new Ext.data.JsonStore({
	    url: '../budgetManager/finishedManager.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
        fields: ['budgetId','budgetYear','budgetMonth','budgetState','filialeId','createId','createDate','submitDate','files']
	});
	this.renderStatus = function(value){
		return OMS.DEPT_STATE_VALUE[value];
	};
	this.renderYear = function(value){
		return OMS.DEPT_YEAR_VALUE[value];
	};
	this.renderMonth = function(value){
		return OMS.DEPT_MONTH_VALUE[value];
	};
	this.renderFiles = function(value){
		var result='';
		if(value){			
			for(var i=0;i<value.length;i++){
				var href='../budgetManager/downloadFile.form?fileId='+value[i].ACCESSORY_ID;
				result+='[<a href="'+href+'">'+value[i].ACCESSORY_NAME+'</>]';
				if(i != value.length-1)
					result+=',&nbsp;';
			}
		}
		return result;
	};
	this.column = [
		{header: 'NO', sortable: true, align: 'right',width: 15,dataIndex: 'budgetId'},
		{header: '年度', sortable: true, align: 'center',width: 10,dataIndex: 'budgetYear',renderer:this.renderYear},
		{header: '月份', sortable: true, align: 'center',width: 10,dataIndex: 'budgetMonth',renderer:this.renderMonth},
		{header: '状态', sortable: true, align: 'center',width: 10,dataIndex: 'budgetState',renderer:this.renderStatus},
		{header: '附件', align: 'left',dataIndex: 'files',renderer:this.renderFiles}
	];
			
	Budget.Finished.superclass.constructor.call(this, {
		title: '已上报预算表',
        region: 'center',
        cm: new Ext.grid.ColumnModel(this.column),
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        tbar: ['->','选择时间:', this.cbYear, this.cbMonth,this.btnSearch],
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        store:this.store,
        viewConfig: { forceFit: true },
        listeners:{
        	rowdblclick : this.onView,
			//render:this.queryBudget
			activate: this.queryBudget
		}
    });
};
Ext.extend(Budget.Finished, Ext.grid.GridPanel, {
	queryBudget:function(btn,event){
		var params={
			start : 0,
			limit : 15,
			budgetYear:this.cbYear.getValue(),
			budgetMonth:this.cbMonth.getValue()
		};
		this.store.load({
			params:params
		});
	},
	onView:function(grid, rowIndex,e){		
		if (this.winView == null) {
			this.winView = new Budget.View(this);
		}
		this.winView.show();
		this.winView.initWin(grid.store.getAt(rowIndex).data);	
	}
});
